package cn.smxy.admin.service.impl;

import cn.smxy.admin.mapper.RequestLogMapper;
import cn.smxy.admin.pojo.RequestLog;
import cn.smxy.admin.service.RequestLogService;
import cn.smxy.param.PageParam;
import cn.smxy.util.R;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class RequestLogServiceImpl implements RequestLogService {

    @Autowired
    private RequestLogMapper requestLogMapper;

    @Override
    public R page(PageParam pageParam) {
        // 参数拆分
        int currentPage = pageParam.getCurrentPage();
        int pageSize = pageParam.getPageSize();
        // 设置分页属性
        IPage<RequestLog> page = new Page<>(currentPage, pageSize);
        page = requestLogMapper.selectPage(page, null);
        // 结果封装
        long total = page.getTotal();
        List<RequestLog> records = page.getRecords();
        R ok = R.ok("查询成功", records, total);
        log.info("RequestLogServiceImpl.page业务结束，结果为:{}","");
        return ok;
    }
}
